<?php
	// For logging usage.
	require_once('service-log.php');	
	
	if (!defined('ROOT_FOLDER')) {
		define('ROOT_FOLDER', dirname(__FILE__) . '/');
		// UPLOAD_FOLDER disesuaikan dengan folder hasil upload file excel.
		define('UPLOAD_FOLDER', ROOT_FOLDER . 'upload/');
		// UPLOAD_FOLDER disesuaikan dengan folder history file excel.
		define('HISTORY_FOLDER', ROOT_FOLDER . 'history/');
	}
		
	// Dalam implementasinya disesuaikan dengan lokasi PHPExcel di dalam aplikasi yang ada.
	require_once(ROOT_FOLDER . 'PHPExcel/PHPExcel.php');
	
	$objReader = PHPExcel_IOFactory::createReader("Excel2007");
	
	if ($handle = opendir(UPLOAD_FOLDER)) {
		while (false !== ($xlsFile = readdir($handle))) {
			if (is_dir($xlsFile))
				continue;
			if (substr($xlsFile, 0, 1) == '.')
				continue;
			echo $xlsFile . "\n";					
			
			/** BEGIN	: Proses data excel **/
			
			/** END 	: Proses data excel **/
			
			setLog('MOVE-FILE : Moving file from ' . UPLOAD_FOLDER . $xlsFile . ' to ' . HISTORY_FOLDER . $xlsFile);
			rename(UPLOAD_FOLDER . $xlsFile, HISTORY_FOLDER . $xlsFile);
		}	
	}
	
	
	
	// End of file